import html2canvas from '../base/html2canvas';

class Snapshot {
	constructor() {}

	getScreenshots(domElement, options) {
		return new Promise((resolve, reject) => {
			try {
				let element = domElement ? domElement : document.body;
				html2canvas(element, options).then(canvas => {
					resolve(canvas);
				});
			} catch (error) {
				reject(error);
			}
		});
	}

	getBase64ImgWidthStream(localStream, customerStreamBox, suffix, quality) {
		return new Promise((resolve, reject) => {
			try {
				let stream = localStream.mediaStream || localStream;
				let video = document.getElementById(customerStreamBox);
				let canvas = document.createElement('canvas');
				let track = stream.getVideoTracks()[0];
				const { height, width } = track.getSettings();
				canvas.height = height;
				canvas.width = width;
				canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
				resolve(canvas.toDataURL(suffix, quality));
			} catch (error) {
				reject(error);
			}
		});
	}
}

export { Snapshot };
